n = int(input().split()[0])
K = [0 for i in range(0, 500)]
Max = 1 << n 
for i in range(0, Max):
	ss = input().split()
	K[i] = ss[0]

ch = input()
Len = len(ch)
Ans = [0 for i in range(0, 500000)]


if(Len % n != 0):
	print("Type Error,Please Check!")
elif ch.isdigit() == 0:
	print("Type Error,Please Check!")
else:
	j = 0
	top = 0
	while(j < Len) :
		temp = 0
		for i in range(0, n):
			temp = (temp << 1) + ord(ch[j + i]) - ord('0')
	#	print(temp)
		Ans[top] = K[temp]
		top = top + 1
		j = j + n
	for i in range(0, top - 1):
		print(Ans[i], end = ' ')
	print(Ans[top - 1])		